# -*- encoding:utf-8 -*-
from service.stockprice.StockPriceBackupCrawler import StockPriceBackupCrawler
from service.stockprice.StockPriceCrawler import StockPriceCrawler
from service.stockprice.StockPriceXueQiuCrawler import StockPriceXueQiuCrawler

__author__ = 'shudong.msd'


# 写入db
def writeToDB():
    print u'开始stockprice 抓取股票价格'
    crawler = StockPriceCrawler()
    crawler.set_target('http://api.money.126.net/data/feed/')
    count = crawler.writeToDB()
    print 'ok!!!'
    return count


# 更新db
def updateDB():
    print u'开始stockprice 更新股票价格'
    crawler = StockPriceCrawler()
    crawler.set_target('http://api.money.126.net/data/feed/')
    print 'ok!!!'
    return crawler.updateDB()

# 写入db
def writeToDB_backup():
    s = StockPriceBackupCrawler()
    s.set_target('http://hq.sinajs.cn/list=')
    return s.writeToDB()

# 更新db
def updateDB_backup():
    s = StockPriceBackupCrawler()
    s.set_target('http://hq.sinajs.cn/list=')
    return s.updateDB()

#雪球
def writeToDB_xueqiu():
    print u'开始stockprice 抓取股票价格'
    a = StockPriceXueQiuCrawler();
    a.set_target("http://xueqiu.com/v4/stock/quote.json?code=")
    count =  a.writeToDB()
    print "ok"
    return count

def updateDB_xueqiu():
    a = StockPriceXueQiuCrawler();
    a.set_target("http://xueqiu.com/v4/stock/quote.json?code=")
    return a.updateDB()

def update_mv():
    print u'开始更新市值'
    a = StockPriceXueQiuCrawler();
    a.set_target("http://xueqiu.com/v4/stock/quote.json?code=")
    count = a.update_market_value()
    print "ok"
    return count



# 测试访问情况
def test_get_page():
    crawler = StockPriceCrawler()
    crawler.set_target('http://api.money.126.net/data/feed/')
    print len(crawler.get_stock_info_json())